/*
    This source file is part of GeNa project.
    Copyright © GeNa project 2008
    For the latest info, see http://code.google.com/p/genaproject/ or  http://lumpyproject.forums-rpg.com

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    Foobar is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with Foobar.  If not, see <http://www.gnu.org/licenses/>. */

#ifndef AXIS_H_INCLUDED
#define AXIS_H_INCLUDED

#ifndef WX_PCH_H_INCLUDED
#include "wx_pch.h"
#endif

class Axis
{
    FreeCamera* m_camera;
    math::matrix4f* m_mat;
    int m_width, m_height;
public:
    Axis(FreeCamera* camera)
    {
        m_camera = camera;
        m_mat = NULL;
    }

    Axis(math::matrix4f &mat)
    {
        m_mat = &mat;
        m_camera = NULL;
    }

    void draw()
    {
        //Adjust Viewport
        glViewport(10, 10, 50, 50);
        glMatrixMode(GL_PROJECTION);
        glLoadIdentity();
        gluPerspective(70, 1, 0.1, 10000);

        //Set view matrix
        glMatrixMode(GL_MODELVIEW);
        glLoadIdentity();
        glTranslatef(0, 0, -4);

        math::matrix4f mat ;
        if( m_camera)
            mat = m_camera->getMatrix();
        else
            mat = *m_mat;
        //mat.m14 = 0; mat.m24 = 0; mat.m34 = 0;
        mat.l[3] = 0; mat.l[7] = 0; mat.l[11] = 0;
        glMultTransposeMatrixf( mat.l);

        //Draw axis
        glDisable(GL_TEXTURE_2D);
        glDisable(GL_DEPTH_TEST);

        glBegin(GL_LINES);
        glColor3f(1.0,0.0,0.0);
        glVertex3f(0,0,0);
        glVertex3f(2,0,0);

        glColor3f(0.0,1.0,0.0);
        glVertex3f(0,0,0);
        glVertex3f(0,2,0);

        glColor3f(0.0,0.0,1.0);
        glVertex3f(0,0,0);
        glVertex3f(0,0,2);
        glEnd();

        glEnable(GL_TEXTURE_2D);
        glEnable(GL_DEPTH_TEST);
    }
};

#endif // AXIS_H_INCLUDED
